package net.media.datafw.utils;

import java.text.SimpleDateFormat;
import java.util.Date;

public class ReadUtil {
	public static int getInt(String strVal, int defaultValue) {
		int value = defaultValue;
		if (strVal != null) {
			try {
				value = Integer.parseInt(strVal);
			} catch (Exception e) {
			}
		}
		return value;
	}

	public static long getLong(String strVal, long defaultValue) {
		long value = defaultValue;
		if (strVal != null) {
			try {
				value = Long.parseLong(strVal);
			} catch (Exception e) {
			}
		}
		return value;
	}

	public static float getFloat(String strVal, float defaultValue) {
		float value = defaultValue;
		if (strVal != null) {
			try {
				value = Float.parseFloat(strVal);
			} catch (Exception e) {
			}
		}
		return value;
	}

	public static double getDouble(String strVal, double defaultValue) {
		double value = defaultValue;
		if (strVal != null) {
			try {
				value = Double.parseDouble(strVal);
			} catch (Exception e) {
			}
		}
		return value;
	}

	public static Date getDate(SimpleDateFormat sdf, String dateValue, Date defaultDate) {
		Date value = defaultDate;
		if (dateValue != null) {
			try {
				value = sdf.parse(dateValue);
			} catch (Exception e) {
			}
		}
		return value;
	}

	public static boolean getBoolean(String strVal, boolean defaultValue) {
		boolean value = defaultValue;
		if (strVal != null) {
			try {
				value = Boolean.parseBoolean(strVal);
			} catch (Exception e) {
			}
		}
		return value;
	}

	public static String getString(String strVal, String defaultValue) {
		String value = defaultValue;
		if (strVal != null && ((strVal = strVal.trim()).length() > 0)) {
			value = strVal;
		}
		return value;
	}
}
